package com.lagou.init;

import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;

import javax.servlet.ServletException;

/**
 *
 */
public class SpringApplication {

    // 创建tomcat，并启动tomcat
    public static void run()  {
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(8080);
        try {
            // 设置项目文件路径，才会进入 onStartup 方法
            tomcat.addWebapp("/","E:\\HomeWork\\spring-boot-homework\\code\\tomcat.8080\\work\\Tomcat\\localhost\\ROOT");
            // 启动tomcat
            tomcat.start();
            System.out.println("tomcat已启动……");

            // 设置tomcat一直存活
            tomcat.getServer().await();
        } catch (LifecycleException e) {
            e.printStackTrace();
        } catch (ServletException e) {
            e.printStackTrace();
        }


    }
}
